﻿package net.wangit.dev.wizard;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.framework.config.BeanFactory;
import net.wangit.framework.config.Mappings;
import net.wangit.framework.config.Pages;
import net.wangit.jdbc.DB;
import net.wangit.util.Checker;
import net.wangit.view.Suite;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class WizardAction extends DomainAction {

	private static final Log log = LogFactory
			.getLog(net.wangit.dev.wizard.WizardAction.class);

	public WizardAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String suiteId = (String) ac.getSessionAttribute(WizardUI.SESSION_KEY);
		if (!Checker.isEmpty(suiteId)) {
			Suite suite = BeanFactory.getSuite(suiteId);
			if (suite != null) {
				suite.create(db, ac);
				Mappings.reload(domain);
				Pages.reload(domain);
			} else {
				log.error((new StringBuilder("suite not found: ")).append(
						suiteId).toString());
				ac.getActionResult().setSuccessful(false);
			}
		} else {
			log.error("suite is null! ");
			ac.getActionResult().setSuccessful(false);
		}
	}

}
